from time import sleep

from litemall_0805.frame.pages.home_page import HomePage
from litemall_0805.frame.utils.utils import repeat_click
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait


class OrderManageList(HomePage):

    def input_order_info(self, order_num):
        self.do_send_keys(order_num, By.XPATH, "//*[@placeholder='请输入订单编号']")

        return self

    def click_search(self):
        self.do_click(By.XPATH, "//*[text()='查找']")

        return self

    def get_search_result(self):
        search_res = self.do_find(By.XPATH, "//*[@class='el-table__row']//*[text()='20220815840990']")
        return search_res.text

    def del_order(self):
        self.wait_repeat_click(By.XPATH, "//*[text()='删除']")

        return self

    def get_del_result(self):
        """
           实现【删除】能的测试结果
           :return: 订单删除成功
        """
        del_element = (By.XPATH, "//*[text()='订单删除成功']")
        del_result = self.wait_visible_locate(del_element)
        return del_result.text
